const db = {
    save(key, value) {
        let projectName = process.env.VUE_APP_TITLE
        localStorage.setItem(projectName + '_' + key, JSON.stringify(value))
    },
    get(key, defaultValue = {}) {
        let projectName = process.env.VUE_APP_TITLE
        try {
            return JSON.parse(localStorage.getItem(projectName + '_' + key)) || defaultValue
        } catch (err) {
            return defaultValue
        }
    },
    remove(key) {
        let projectName = process.env.VUE_APP_TITLE
        localStorage.removeItem(projectName + '_' + key)
    },
    clear() {
        // 为了使多个项目 能在同一个域下 独立使用， 清除缓存时，需要区分来
        let projectName = process.env.VUE_APP_TITLE
        for (const key in localStorage) {
            if (key.indexOf(projectName) !== -1) {
                console.log(key)
                localStorage.removeItem(key)
            }
        }
    }
}

export default db
